﻿/*-----------------------------------------------
// File: LoadingKit.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

public class LoadingKit : MonoBehaviour
{
    public float duration;

    public CGKit cgKit;

    public GameObject logoObj;

    public static bool isLoadingKit;

    void Start()
    {
        StaticData.httpServer = ServerConfig.GetServerUrl();
        Show();
    }



    public void Show()
    {
        isLoadingKit = true;
        gameObject.SetActive(true);
        Invoke("ShowLogo",0.1f);
        Invoke("ToLogin", duration);
        Invoke("ShowLoading", (duration - 1f) > 0 ? duration - 1f : 0.1f);

    }

    public void ShowLogo()
    {
        logoObj.SetActive(true);
        UIAutoSize.Instance.ShowMaskUI(false);
        if (GameConfig.Instance.IsFirstBattleEnter)
        {
            FirstCheckPointUtil.CheckPoint(EnterGameCheckPointEnum.EnterLogo);
        }
    }

    public void ShowLoading()
    {
        LoadingPanel.Instance.ShowLoadingPre();
        UIAutoSize.Instance.ShowMaskUI(false);
    }

    void ToLogin()
    {
        //cgKit.gameObject.SetActive(true);
        cgKit.ShowCG();
        if (GameConfig.Instance.IsFirstBattleEnter)
        {
            Destroy(gameObject);
        }
        else
        {
            //yield return new WaitForSeconds(0.5f);
            GameObject.Destroy(gameObject, 0.5f);
        }
        StartCoroutine(ShowMAskUIAutoSize());
    }
    IEnumerator ShowMAskUIAutoSize()
    {
        yield return new WaitForSeconds(0.3f);
        isLoadingKit = false;
        UIAutoSize.Instance.ShowMaskUI(true);
    }
}
